package com.jiayang.hhotel.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.jiayang.hhotel.R;
import com.jiayang.hhotel.bean.AuditListModel;
import com.jiayang.hhotel.util.LogUtil;
import com.yanzhenjie.recyclerview.swipe.SwipeMenuAdapter;

import java.util.List;

/**
 * Created by Administrator on 2017/5/25 0025.
 * 查账子列表适配器
 */

public class AuditItemAdapter extends SwipeMenuAdapter<AuditItemAdapter.ViewHolder> {

    private Context t;
    private List<AuditListModel.PTransDetailListDtosBean> mList;
    private int type;

    public AuditItemAdapter(Context context, List<AuditListModel.PTransDetailListDtosBean> list,int type){
        this.t=context;
        this.mList=list;
        this.type=type;
    }

    @Override
    public View onCreateContentView(ViewGroup parent, int viewType) {
        return LayoutInflater.from(t).inflate(R.layout.audit_tab_list_item,null);
    }

    @Override
    public ViewHolder onCompatCreateViewHolder(View realContentView, int viewType) {
        return new ViewHolder(realContentView);
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        AuditListModel.PTransDetailListDtosBean model=mList.get(position);
        LogUtil.showLog("model="+model.toString());
        switch (type){
            case 1://
            case 4://
                holder.remarks.setVisibility(View.VISIBLE);
                holder.dateTime.setVisibility(View.VISIBLE);
                holder.dateTime.setText(model.getDate());
                holder.project.setText(model.getTrndescp());
                holder.money.setText(model.getAmount()+"");
                holder.remarks.setText(model.getComment());
                break;
            case 3://
                holder.remarks.setVisibility(View.GONE);
                holder.dateTime.setVisibility(View.VISIBLE);
                holder.dateTime.setText(model.getRoom());
                holder.project.setText(model.getTrndescp());
                holder.money.setText(model.getAmount()+"");
                break;
            case 2://
            case 5://
                holder.remarks.setVisibility(View.GONE);
                holder.dateTime.setVisibility(View.GONE);
                holder.project.setText(model.getTrndescp());
                holder.money.setText(model.getAmount()+"");
                break;
        }
    }
    //获取金额总计
    public double getTotalMoney(){
        double money=0.00;
        for(int i=0;i<mList.size();i++){
            money+=mList.get(i).getAmount();
        }
        return money;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public int getItemCount() {
        return mList.size();
    }

    class ViewHolder extends RecyclerView.ViewHolder{
        TextView dateTime;
        TextView project;
        TextView money;
        TextView remarks;

        public ViewHolder(View item){
            super(item);
            dateTime= (TextView) item.findViewById(R.id.tv_date_time);
            project = (TextView) item.findViewById(R.id.tv_project);
            money= (TextView) item.findViewById(R.id.tv_money);
            remarks = (TextView) item.findViewById(R.id.tv_remarks);
        }
    }
}
